﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Morro.VPN.Core
{
    public static class AliveECGService
    {
        public static AliveECGData LoadDataFromFile(string filePath)
        {
            try
            {
                StreamReader sr = new StreamReader(filePath, Encoding.Default);

                //Elapsed Time (ms), RR (ms), Heart Rate (bpm)
                sr.ReadLine();

                List<int> time = new List<int>();
                List<int> rr = new List<int>();


                while (!sr.EndOfStream)
                {

                    string line = sr.ReadLine();
                    string[] listSplit = line.Split(',');
                    if (listSplit.Length != 3)
                    {
                        //error
                    }

                    int timeValue = Convert.ToInt32(listSplit[0]);
                    int rrValue = Convert.ToInt32(listSplit[1]);

                    time.Add(timeValue);
                    rr.Add(rrValue);
                }

                sr.Close();
                
                return new AliveECGData(time,rr);
            }
            catch (Exception exception)
            {
                throw;
            }

            return null;
        }
    }
}
